package main

import (
	"os"

	"github.com/gin-gonic/gin"
	"github.com/kpango/glg"
	"gopkg.in/alecthomas/kingpin.v2"
)

var (
	BasePath    = kingpin.Flag("path", "base path to place result data").Default(".").String()
	Port        = kingpin.Flag("port", "port to listen").Default("9099").Short('p').String()
	LogFile     = kingpin.Flag("log", "name of log file").Default("crmlog-query.log").Short('l').String()
	EverlogPort = kingpin.Flag("eport", "port of everylog service").Default("80").String()
	EverlogIp   = kingpin.Flag("eip", "ip of everylog service").Default("127.0.0.1").String()
	ProPort     = kingpin.Flag("pport", "Prometheus port").Default("10112").String()
	AuthPath	= kingpin.Flag("auth", "path to place password file").Default(".").String()
)

func main() {
	kingpin.Parse()
	c, err := NewController(*BasePath, *LogFile)
	if err != nil {
		glg.Errorf("queryService.main: Failed to new controller: %v", err)
		os.Exit(1)
	}
	defer c.Close()
	go c.ms.ListenPrometheus(":"+*ProPort)
	router := gin.Default()
	router.GET("/REST/HTableService", c.GetHandler)
	router.Run(":" + *Port)
}
